using Mapster;
using SmartCommunity.Models;
using System.ComponentModel.DataAnnotations;

namespace SmartCommunity.Services.Community
{
    #region DTO属性映射
    /// <summary>
    /// 属性映射 CommunityDtoRegister
    /// </summary>
    public class CommunityDtoRegister : IRegister
    {
        public void Register(TypeAdapterConfig config)
        {
            // config.ForType<CommunityEntity, CommunityDto>().Map(d => d.DeptName, s => s.Dept.DeptName, s => s.Dept != null);
        }
    }
    #endregion

    #region 数据传输对象 CommunityDto
    /// <summary>
    /// 数据传输对象：社区
    /// </summary>
    public class CommunityDto : BaseDto
    {
        /// <summary>
        /// 社区ID
        /// </summary>
        public Guid CommunityId { get; set; }

        /// <summary>
        /// 社区名称
        /// </summary>
        [Required(ErrorMessage = "社区名称不能为空")]
        [StringLength(100, ErrorMessage = "社区名称 长度不能超过 100.")]
        public string CommunityName { get; set; } = string.Empty;

        /// <summary>
        /// 负责人姓名
        /// </summary>
        [StringLength(45, ErrorMessage = "负责人姓名 长度不能超过 45.")]
        public string? ManagerName { get; set; }

        /// <summary>
        /// 负责人电话
        /// </summary>
        [StringLength(20, ErrorMessage = "负责人电话 长度不能超过 20.")]
        public string? ManagerTel { get; set; }

        /// <summary>
        /// 成立日期 
        /// </summary>
        public DateOnly CreatedDate { get; set; }

        /// <summary>
        /// 是否作废
        /// </summary>
        public bool Disabled { get; set; }

        /// <summary>
        /// 备注说明
        /// </summary>
        [StringLength(255, ErrorMessage = "备注说明 长度不能超过 255.")]
        public string? Remark { get; set; }

    }
    #endregion

    #region 数据查询对象
    /// <summary>
    /// 查询模型：社区
    /// </summary>
    public class CommunityQuery : AbstractQuery<CommunityEntity>
    {
        /// <summary>
        /// 主键ID多选查询
        /// </summary>
        public IEnumerable<Guid> Ids { get; set; } = [];


        /// <summary>
        /// 根据查询条件添加查询表达式
        /// </summary>
        protected override void MergeQueryExpression()
        {
            AddExpression(Ids.Any(), e => Ids.Contains(e.CommunityId));
            AddSearchExpression(s => o => o.CommunityName.Contains(s) || (o.ManagerName ?? "").Contains(s));
        }
    }
    #endregion
}
